package sort;

import dbmanager.DBManager;
import dbmanager.GetIdName;

public class ArraySort
{
	DBManager db;
	GetIdName gin;
	public ArraySort(DBManager db) 
	{
		this.db = db;
		gin = new GetIdName(db);
	}
	public String[] sortArrayIndex(String[] recordSet,int indexOfField) 
	{
		int min = 0;
		
		for(int j=0;j<recordSet.length;j++)
		{
			int indexOfSort = 0;
			
			String []Values = recordSet[j].split("\t");
			try
			{
				indexOfSort = Integer.parseInt(gin.getItem(Values[indexOfField]));
			}
			catch (Exception e)
			{
				indexOfSort=0;
			}
			
			min = indexOfSort;
			int Precedence = 0;
			for(int i=j+1;i<recordSet.length;i++)
			{
				String splitrecordSet[]=recordSet[i].split("\t");
				try
				{
					Precedence = Integer.parseInt(gin.getItem(splitrecordSet[indexOfField]));
				} catch (Exception e) 
				{
					Precedence =0;
				}
				if(min > Precedence)
				{
					String temp = recordSet[j];
					recordSet[j] = recordSet[i];
					recordSet[i] = temp;
					min = Precedence;
				}
			}
		}
		return recordSet;
	}

}
